#include "syscall.h"
#include "user.h"

#define Dim 	20	/* sum total of the arrays doesn't fit in 
			 * physical memory 
			 */
int A[Dim][Dim];
int B[Dim][Dim];
int C[Dim][Dim];

int D[Dim][Dim];
int E[Dim][Dim];
int F[Dim][Dim];

   
void matTest1();
void matTest2();


int main(){
	int whichTest, matmultNO, sortNO, i;
	Printf("\n---------------------THIS IS TEST FOR PROJECT 3 STEP 3 TEST:-----------------------");
	Printf("\n1->exec multiple matmults");
	Printf("\n2->exec multiple sorts");
	Printf("\n3->fork multiple matmults");
	Printf("\n4->fork multiple sorts");
	Printf("\nPlease enter 1,2,3,4");
	/*Printf("\n1 is choosed");*/
	whichTest = InputInt();
	/*whichTest = 3;*/
	switch(whichTest){
		case 1:
		Printf("\nPlease input the number of matmults you want to exec");
		matmultNO = InputInt();
		/*matmultNO = 1;*/
		for(i=1;i<=matmultNO;i++){
			Printf("\nExecing the %dth matmult....",i);
			Exec("../test/matmult",sizeof("../test/matmult"));
		}
		break;
		
		case 2:
		Printf("\nPlease input the number of sorts you want to exec");
		sortNO = InputInt();
		for(i=1;i<=sortNO;i++){
			Printf("\nExecing the %dth sort....",i);
			Exec("../test/sort",sizeof("../test/sort"));
		}
		break;
		case 3:
		/*Printf("\nPlease input the number of matmults you want to fork");*/
		Printf("\nForking 2 matmult...");
		/*matmultNO = InputInt();*/
/*		for(i=1;i<=matmultNO;i++){
*			Printf("\nForking the %dth sort....",i);
*			Fork(matTest);
*		}
*/
		Fork(matTest1);
		Fork(matTest2);
		break;
		case 4:
		Printf("\nPlease input the number of sorts you want to fork");
		sortNO = InputInt();
		for(i=1;i<=sortNO;i++){
			Printf("\nExecing the %dth sort....",i);
			/*Fork(sortTest);*/
		}
		break;		
		default:
		Printf("\nWrong input, please re-run the program.");
	}
	return 0;
}

void matTest1(){
	int i, j, k;
    for (i = 0; i < Dim; i++)		/* first initialize the matrices */
	for (j = 0; j < Dim; j++) {
	     A[i][j] = i;
	     B[i][j] = j;
	     C[i][j] = 0;
	}

    for (i = 0; i < Dim; i++)		/* then multiply them together */
	for (j = 0; j < Dim; j++)
            for (k = 0; k < Dim; k++)
		 C[i][j] += A[i][k] * B[k][j];
	Printf("\n\nThe C[Dim-1][Dim-1] is %d\n\n",C[Dim-1][Dim-1]);
    Exit(0);		/* and then we're done */
}
void matTest2(){
	int a, b, c;
    for (a = 0; a < Dim; a++)		/* first initialize the matrices */
	for (b = 0; b < Dim; b++) {
	     D[a][b] = a;
	     E[a][b] = b;
	     F[a][b] = 0;
	}

    for (a = 0; a < Dim; a++)		/* then multiply them together */
	for (b = 0; b < Dim; b++)
            for (c = 0; c < Dim; c++)
		 F[a][b] += D[a][c] * E[c][b];
	Printf("\n\nThe F[Dim-1][Dim-1] is %d\n\n",F[Dim-1][Dim-1]);
    Exit(0);		/* and then we're done */
}
